package com.hw.protocol.tool.config;

/**
 * @author : lihy
 * @date : 2023/9/11 9:57
 * description: 设备异常
 */
public enum DevExceptionEnum {

    /**
     * meterType = 0
     */
    UNREAD_DATA(0, "未读取到数据"),
    /**
     * flag[0] bit0,1 = 00
     */
    VALVE_OPEN(1, "阀门开"),
    /**
     * flag[0] bit0,1 = 01
     */
    VALVE_CLOSE(2, "阀门关"),
    /**
     * flag[0] bit0,1 = 11
     */
    VALVE_EXCEPTION(3, "阀门异常"),
    /**
     * flag[0] bit2 = 1
     */
    CORRECTOR_VOLTAGE_LOWER(4, "修正仪电压不足"),
    /**
     * flag[0] bit3 = 1(5000/5100)
     * flag[0] bit4 = 1(6010)
     */
    EQUIPMENT_ELEMENT_CLOSED(5, "设备外供电中断"),
    /**
     * flag[0] bit3 = 1(6130/6131)
     */
    EQUIPMENT_BATTERY_LOWER(6, "设备电池电压不足"),
    /**
     * flag[3] != 0(6130/6131)
     */
    CORRECTOR_METER_ANOMALY(7, "修正仪表异常"),
    /**
     * status bit0 = 1(10000)
     */
    HARD_WARE_ERROR(11, "硬件错误"),
    /**
     * status bit1 = 1(10000)
     */
    LOW_ALERT(12, "低报警"),
    /**
     * status bit1 = 1(10000)
     */
    HIGH_ALERT(13, "高报警"),
    UNKNOWN(9999, "未知异常");

    private int code;
    private String label;

    DevExceptionEnum(int code, String label) {
        this.code = code;
        this.label = label;
    }

    public int getCode() {
        return code;
    }

    public String getLabel() {
        return label;
    }

    public static DevExceptionEnum getException(int code){
        for (DevExceptionEnum value : DevExceptionEnum.values()) {
            if(value.code == code){
                return value;
            }
        }
        return UNKNOWN;
    }
}
